// 外观数列

package Leetcode;

class solution_038 {
    public String countAndSay(int n) {
        String result = "1";
        for (int i = n; i > 1; i--) {
            result = count(result);
        }
        return result;
    }

    public String count(String s) {
        char[] number = new char[s.length() + 1];
        int[] nums = new int[s.length() + 1];
        int len = 0;
        for (char c : s.toCharArray()) {
            if (number[len] == c) {
                nums[len]++;
            } else {
                len++;
                number[len] = c;
                nums[len]++;
            }
        }
        String result = "";
        for (int i = 1; i <= len; i++) {
            result = result + nums[i] + number[i];
        }
        return result;
    }

    // public static void main(String[] args) {
    // String s = "121";
    // System.out.println(count(s));
    // }
}

public class Solution038 {

}
